<?php
/*
 * @Descripttion:
 * @Version: 1.0
 * @Author: wangph
 * @Date: 2021-03-31 09:46:02
 * @LastEditors: wangph
 * @LastEditTime: 2021-04-29 10:24:44
 */

namespace app\api\controller\v1;

use service\ApiReturn;
use app\api\controller\Base;
use think\Db;


class Qrcode extends Base
{

    /*
     * 生成二维码
     */
    public function index($data = [], $user = [])
    {
        $invite_code = Db::name("user_info")->where([
            'user_id' => $user['id']
        ])->value("invite_code");
        $url = config('web_site_domain') . '/h5/registered/index.html?id=' . $invite_code;
        
        $code_url = addons_action('Qrcode/Qrcode/generate', [$url]);
        if (!$code_url) {
            throw new \Exception(lang('生成分享二维码失败'));
        }
        $info['qrcode_url'] = config('web_site_domain') . $code_url;
        $info['url'] = $url;
        return ApiReturn::r(1, $info, 'ok');
    }

}
